package com.honey.compilation.sql.ddl;

import com.honey.compilation.sql.SqlKeyWord;
import com.honey.compilation.sql.SqlScript;
import com.honey.compilation.sql.ValueElement;
import com.honey.core.builder.CharacterBuilder;
import com.honey.core.builder.CharacterBuilderFactory;
import com.honey.core.compiler.CompilationException;
import com.honey.core.utils.StringUtility;

/**
 * SQL 92中schema定义:<br />
 * &lt;schema definition&gt;    ::= <br />
 * CREATE SCHEMA &lt;schema name clause&gt;<br />
 * [ &lt;schema character set specification&gt; ]<br />
 * [ &lt;schema element&gt; ... ]<br /><br />
 * 
 * 注意:<br />
 * SQL 92中没有database的概念,所以也没有定义 create database;SQL 92中定义的是schema,在在某意义上可以理解为database.例如:<br />
 * mysql中 schema等同于database<br />
 *
 * @author Administrator
 *
 */
public class CreateSchema extends  Create implements SqlScript {
	
	/** schema名称 */
	private ValueElement schemaName;
	
	/** 附加信息 */
	private ValueElement append;
	
	/**
	 * 构造函数
	 * @param schemaName schema名称
	 */
	public CreateSchema(String schemaName){
		this.schemaName =new ValueElement( schemaName );
	}

	/**
	 * 获取附加信息
	 * @return
	 */
	public String getAppend() {
		return append.getValue();
	}

	/**
	 * 设定附加信息
	 * @param append
	 */
	public void setAppend(String append) {
		this.append =new ValueElement( append );
	}

	/*
	 * (non-Javadoc)
	 * @see com.honey.core.dom.sql.ddl.Create#compiledContent(int)
	 */
	@Override
	public CharacterBuilder compiledContent(int indentLevel) throws CompilationException {
		CharacterBuilder answer = CharacterBuilderFactory.createC16StringBuilder();
		if( StringUtility.stringHasValue(schemaName.getValue() ) ){
			answer.append(super.compiledContent(indentLevel))
			.append(SqlKeyWord.SCHEMA)
			.append(schemaName);
			if( append != null ){
				answer.append(append) ;
			}
			answer.append(SqlKeyWord.OPERATION_SEMICOLON);
		}else{
			return CharacterBuilderFactory.createC16StringBuilder();
		}
		return answer;
	}
}
